#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# Last modified: 

"""docstring
"""

import urllib,urllib2
import cookielib
from BeautifulSoup import BeautifulSoup

__revision__ = '0.1'
def login():
    '''登录脚本'''
    print 'Trying to login...'

    cookie = cookielib.CookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie),urllib2.HTTPHandler)
    urllib2.install_opener(opener)

    postdata = urllib.urlencode({'email':'',\
                                  'password':'',\
                                  'origURL':'http://www.renren.com/home',\
                                  'domain':'renren.com'\
                                  })
#    print postdata
    req = urllib2.Request(url = 'http://www.renren.com/PLogin.do',\
                         data = postdata
                         )
    req.addheaders = [('User-Agent','Mozilla/5.0 (X11; Linux i686; rv:5.0) Gecko/20100101 Firefox/5.0'),\
            ('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),\
            ('Accept-Encoding','gzip,deflate'),\
            ('Referer','http://renren.com/Login.do')]
#    req.add_header('User-Agent','Mozilla/5.0 (X11; Linux i686; rv:5.0) Gecko/20100101 Firefox/5.0')



    print '....login form submitted'
    result = urllib2.urlopen(req)
    if result.geturl() == 'http://www.renren.com/home':
        print '...login succeed!'
    else :
        print 'login failed...'

login()
post = urllib2.urlopen('http://blog.renren.com/NewEntry.do').read()
soup = BeautifulSoup(post)
postid = soup.find('input',{'id':'postFormId'})
print postid['value'],type(postid['value'])
#form = soup('form')
#print form
